/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React from 'react';
import { Upload } from 'antd';
import { crypto } from '@/utils/encryption';

const UploadWithCrypto = props => {
  const { action, nonceKey, ...restProps } = props;
  const actionPromise =
    typeof action === 'string'
      ? () =>
          crypto({
            url: action,
            options: {
              nonceKey,
              data: restProps.data,
            },
          })
      : '';

  return (
    <Upload action={actionPromise} {...restProps}>
      {props.children}
    </Upload>
  );
};

export default UploadWithCrypto;
